package com.bdsy.business.controller;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.bdsy.api.annotation.IgnoreAuth;
import com.bdsy.business.model.UserIntegrals;
import com.bdsy.business.service.UserIntegralsService;
import com.bdsy.common.annotation.Json;
import com.bdsy.common.utils.Result;
import com.bdsy.system.annotation.SysLog;

/**
 * 等級
 * @author MING
 * @date 2018年2月6日 下午2:48:21
 */

@Controller
@RequestMapping(value = {"${web.adminPath}", "${web.appPath}"})
public class UserIntegralsController {

	@Autowired
	UserIntegralsService userIntegralsService;
	

	/**
	 * 查询当前用户会员等级信息
	 */
	@IgnoreAuth
	@Json
	@RequestMapping(value = "userIntegralsByUserId")
	public Object userIntegralsByUserId(String userId) {
		Map<String,Object> map = new LinkedHashMap<>();
		List<UserIntegrals> UserIntegrals = userIntegralsService.selectUserIntegralsByUserId(userId);
		map.put("code", 200);
		map.put("msg", "success");
		map.put("data", UserIntegrals);
		return map;
	}
	
	/**
	 * 修改当前用户会员信息
	 */
	@IgnoreAuth
	@Json
	@RequestMapping(value = "updateIntegralsByUserId")
	public Object updateIntegralsByUserId(UserIntegrals userIntegrals) {
		boolean result = userIntegralsService.update(userIntegrals);
		if (result) {
			return Result.ok("updateSuccess");
		} else {
			return Result.error("updateFail");
		}
	}
	
	/**
	 * 添加当前用户会员信息 -- 测试使用 
	 */
	@Json
	@RequestMapping(value = "insertUserIntegrals")
	public Object insertUserIntegrals(UserIntegrals userIntegrals) {
		Map<String,Object> map = new LinkedHashMap<>();
		boolean result = userIntegralsService.insert(userIntegrals);
		map.put("code", 200);
		map.put("msg", "success");
		map.put("data", result);
		return map;
	}
	
}
